<?php

namespace app\api\model;

use app\exceptions\ApiException;
use think\Model;

/**
 * Massif
 */
class Massif extends Model
{
    // 表名
    protected $name = 'massif';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    public function getMassif($params)
    {
        $land_id = $params['land_id'] ?? '';
        $land = (new Land())->where(['id' => $land_id])->find();
        if (!$land) {
            throw new ApiException('数据不存在');
        }
        $massif = self::where(['land_id' => $land_id, 'status' => 1])
            ->field('id,name,image,land_id,price,is_lock')
            ->order('id asc')->select();
        foreach ($massif as &$val) {
            $val['image'] = env('domain.image_url') . $val['image'];
        }
        //查询土地的信息
        $land = (new Land())->where(['id' => $land_id])->find();
        $data['detail_image'] = env('domain.image_url') . $land['detail_image'];
        $data['notice'] = $land['notice'];
        $data['content'] = $land['content'];
        $data['list'] = $massif;
        return api_message($data);
    }
}